package com.hpeu_12.day1231_homework;

/**
 * 第七题、请根据以下代码（见下一页）自行定义能满足需要的MyDate类，在MyDate类中覆盖equals方法，
 * 其 判断当两个MyDate类型对象的年月日都相同时，结果为true，否则为false。public boolean equals(Object o)。
 */
class MyDate{
    int year;
    int month;
    int day;

    public MyDate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    @Override
    public boolean equals(Object o) {
        if (o==null) return false;
        if(o instanceof MyDate){
            MyDate myDate = (MyDate)o;
            if(this.year==myDate.year&&this.year==myDate.month&&this.day==myDate.day){
                return true;
            }else return false;
        }else return false;
    }
}
public class DuoTaiTest6 {
    public static void main(String[] args) {
        MyDate m1 = new MyDate(2021,1,3);
        MyDate m2= new MyDate(2021,1,2);
        if (m1==m2){
            System.out.println("m1==m2");
        }else {
            System.out.println("m1!=m2");
        }
        if(m1.equals(m2)){
            System.out.println("m1 is equals to m2");
        }else {
            System.out.println("m1 is not equals to m2");
        }

    }
}
